﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public class TweenActionSequence: TweenActionBase
{
    private TweenActionBase[] actions;
    private int curIndex = 0;
    private float passActionsTime = 0;
    public TweenActionSequence(TweenActionBase[] actions)
    {
        this.actions = actions  ;
        float sum = 0;
        for(int i=0;i<actions.Count();i++)
        {
            sum += actions[i].totalTime;
        }
        totalTime = sum;
    }
    public override void OnUpdate(float schedule) {
        if (curIndex >= actions.Count())
            return;
        TweenActionBase curAction = actions[curIndex];

        if(curAction.first)
        {
            curAction.first = false;
            curAction.OnStart();
        }

        float curSchedule;
        if (curAction.totalTime > 0)
            curSchedule = Math.Max(0, Math.Min(1, (schedule*totalTime - passActionsTime) / curAction.totalTime));
        else
            curSchedule = 1;

        curAction.OnUpdate(curSchedule);

        if(schedule * totalTime - passActionsTime> curAction.totalTime)
        {
            curIndex++;
            passActionsTime = schedule*totalTime;
        }
    }
}

